package model

import (
	"fmt"
	"gorm.io/gorm"
)

type ModelInfo struct {
	gorm.Model
	Name string `gorm:"type:varchar(128);not null"`
}

func (ModelInfo) TableName() string {
	return "model_info"
}

func ListModelInfos(db *gorm.DB) ([]*ModelInfo, error) {
	var modelInfos []*ModelInfo
	err := db.Find(&modelInfos).Error
	if len(modelInfos) == 0 {
		return nil, fmt.Errorf("no model found")
	}
	return modelInfos, err
}

func ListModelInfoByName(db *gorm.DB, name string) ([]*ModelInfo, error) {
	var modelInfos []*ModelInfo
	err := db.Where("name = ?", name).Find(&modelInfos).Error
	if len(modelInfos) == 0 {
		return nil, fmt.Errorf("no model found")
	}
	return modelInfos, err
}
